package kr.ac.mju.mdc.mjuapp.login;

import java.util.List;

import kr.ac.mju.mdc.mjuapp.R;
import net.htmlparser.jericho.Element;
import android.content.Context;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

/**
 * @author davidkim
 *
 */
public class LoginManager {
	/**
	 * @param entity
	 * @return
	 */
	public static boolean parseLoginHTML(List<Element> elementsList, String loginSuccess) {
		try {
			// element check
			if (elementsList != null) {
				for (Element element : elementsList) {
					String parseResult = element.getContent().toString();
					// tag check
					if (parseResult.contains(loginSuccess))
						return true;
					else
						return false;
				}
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * @return
	 */
	public static boolean checkLogin(Context context) {
		// CookieSyncManager
		CookieSyncManager.createInstance(context);
		if (CookieManager.getInstance().hasCookies()) {
			if ((CookieManager.getInstance().getCookie(context.getString(R.string.url_cookie_mobile_01)) != null)
					&& (CookieManager.getInstance().getCookie(context.getString(R.string.url_cookie_mobile_02)) != null))
				return true;
			else
				return false;
		} else
			return false;
	}
}
/* end of file */
